package com.bq.gametrade.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bq.gametrade.GameTradeApplication;
import com.bq.gametrade.R;
import com.bq.gametrade.bean.HomeTradingSell;
import com.bq.gametrade.bean.RedEnvelopeListDetails;
import com.bq.gametrade.bean.RedEnvelopeRecordsDetails;
import com.bq.gametrade.utils.Base64Util;
import com.bq.gametrade.utils.FormatUtil;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

/**
 * @author Feel on 2016/11/29 11:05
 */

public class RedEnvelopeRecordAdapter extends BaseAdapter {


    private ArrayList<RedEnvelopeRecordsDetails> items;
    private Context context;
    private GameTradeApplication application;

    public RedEnvelopeRecordAdapter(Context context, ArrayList<RedEnvelopeRecordsDetails> items,GameTradeApplication application) {
        this.context = context;
        this.items = items;
        this.application = application;
    }

    public void setData(ArrayList<RedEnvelopeRecordsDetails> items){
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_redenveloperecords_item, null);
            viewHolder.tvUserName = (TextView) convertView.findViewById(R.id.tv_UserName);
            viewHolder.tvTime = (TextView) convertView.findViewById(R.id.tv_redEnvelopeTime);
            viewHolder.tvNum = (TextView) convertView.findViewById(R.id.tv_num);
            viewHolder.ivTicket = (ImageView) convertView.findViewById(R.id.iv_ticket);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        RedEnvelopeRecordsDetails details = items.get(position);
        viewHolder.tvTime.setText(details.ctime);
        if(details.revice_user.equals(application.getUserInfo().account)){
           viewHolder.tvUserName.setText(Base64Util.decodeStr(details.send_uname));
        }else {
            viewHolder.tvUserName.setText("普通红包");
        }
        if(details.type.equals("0")){
            viewHolder.ivTicket.setVisibility(View.GONE);
            viewHolder.tvNum.setText(details.num+"元");
        }else {
            viewHolder.tvNum.setText(details.num);
            viewHolder.ivTicket.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    class ViewHolder {
        TextView tvUserName;
        TextView tvTime;
        TextView tvNum;
        ImageView ivTicket;
    }
}
